﻿
// Note that DLL reference order is very important
#r @"C:\Users\Mira\Source\Repos\Spinula\Debug\SpikingNeuronLib.dll"
#r @"C:\Users\Mira\Source\Repos\Spinula\SpikingAnalyticsBaseLib\bin\Debug\SpikingAnalyticsBaseLib.dll"
#r @"C:\Users\Mira\Source\Repos\Spinula\SpikingAnalyticsLib\bin\Debug\SpikingAnalyticsLib.dll"
#I @"C:\Users\Mira\Source\Repos\Spinula\packages\RProvider.1.0.12"
#load "RProvider.fsx"
#I @"C:\Users\Mira\Source\Repos\Spinula\packages\Deedle.1.0.0"
#load "Deedle.fsx"
#r @"C:\Users\Mira\Source\Repos\Spinula\SpikingVisualisationRLib\bin\Debug\SpikingVisualisationRLib.dll"    // references Deedle
#r @"C:\Users\Mira\Source\Repos\Spinula\SpikingAnalyticsFrameLib\bin\Debug\SpikingAnalyticsFrameLib.dll"    // references Deedle

open System
open System.IO
open SpikingAnalyticsLib
open SpikingVisualisationRLib

let TestBackgroundPatternGenerator (backgroundFrequency:int) outputFilePath =

    let verbose = true
    let runSeconds = 5
    let showOnlyForegroundEvents = false

    // create a new network with no connections between neurons
    let network = CrossbarNetwork.CreateAdHocNetwork(CrossbarNetworkSpecifier.N1000_Unconnected_Network, None, verbose)

    // run the network with background stimulation but no input pattern and collect firing data
    network.Run(runSeconds, None, backgroundFrequency)

    // select the third one second frame of firing data (include background events)
    let thirdFrameData = network.OneSecondEventCollector.SelectRange(2000, 3000, showOnlyForegroundEvents)

    // save the data
    thirdFrameData.Save(outputFilePath)

    // show the data as a spike raster
    SpikeVisualisation.ShowSpikeRaster(thirdFrameData.AllEventPairs)

let outputFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
let outputFilePath = Path.Combine(outputFolder, "temp.txt")
TestBackgroundPatternGenerator 10 outputFilePath
